package com.kaussoft.lolblog.vo;

import java.io.Serializable;
import java.util.Set;

/** 
 * 		@hibernate.class
 * 		 table="PART"
 */
public class Part implements Serializable {

	// serialVersionUID
	private static final long serialVersionUID = 1L;
	
	// hashCode
	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private Integer partid;
	
	// fields
	private String partname;
	private String partdesc;
	
	// many to one
	private Wblog belongTo;
	
	// collections
	private Set<Article> articles;
	
	/** default constructor */
	public Part() {
		
	}

	/** primary key constructor */
	public Part(Integer partid) {
		this.setPartid(partid);
	}
	
	/** required fields constructor */
	public Part(Integer partid, String partname, String partdesc) {
		this.setPartid(partid);
		this.setPartname(partname);
		this.setPartdesc(partdesc);
	}

	/**
	 * 		@hibernate.set
	 * 		 lazy="true"
     *       inverse="true"
     *       cascade="all"
     *      @hibernate.key
     *       column="PART_ID"
     *      @hibernate.one-to-many
     *       class="com.kaussoft.lolblog.vo.Article"
	 */
	public Set<Article> getArticles() {
		return articles;
	}

	public void setArticles(Set<Article> articles) {
		this.articles = articles;
	}

	/**
	 * 		@hibernate.property
	 * 		 column="PART_DESC"
	 */
	public String getPartdesc() {
		return partdesc;
	}

	public void setPartdesc(String partdesc) {
		this.partdesc = partdesc;
	}

	/**
	 * 		@hibernate.id
	 * 		 column="PART_ID"
	 * 		 generator-class="native"
	 * 		 type="java.lang.Integer"
	 * 		 unsaved-value=null
	 * 		@hibernate.generator-param name="sequence" value="SQ_PART_ID"
	 */
	public Integer getPartid() {
		return partid;
	}

	public void setPartid(Integer partid) {
		this.partid = partid;
		this.hashCode = Integer.MIN_VALUE;
	}

	/**
	 * 		@hibernate.property
	 * 		 column="PART_NAME"
	 */
	public String getPartname() {
		return partname;
	}

	public void setPartname(String partname) {
		this.partname = partname;
	}
	
	/**
	 *		@hibernate.many-to-one
	 *		 column="WBLOG_ID"
	 *		 class="com.kaussoft.lolblog.vo.Wblog"
	 *		 not-null="true"
	 */
	public Wblog getBelongTo() {
		return belongTo;
	}

	public void setBelongTo(Wblog belongTo) {
		this.belongTo = belongTo;
	}
	
	public boolean addToArticles(Object obj) {
		if (null == obj)
			return false;
		if (!(obj instanceof Article)) 
			return false;
		else {
			Article aObj = (Article)obj;
			if (null == this.articles) 
				this.articles = new java.util.HashSet<Article>();
			return this.articles.add(aObj);
		}
	}

	public boolean equals(Object obj) {
		if (null == obj) 
			return false;
		if (!(obj instanceof Part)) 
			return false;
		else {
			Part aObj = (Part) obj;
			if (null == this.getPartid() || null == aObj.getPartid()) 
				return false;
			else 
				return (this.getPartid().equals(aObj.getPartid()));
		}
	}
	
	public int hashCode() {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getPartid()) 
				return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getPartid().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}

	public String toString() {
		return super.toString();
	}
}
